import {debounce} from './util'
import BackTop from 'components/content/backTop/BackTop'

export const scrollRefreshMixin = {
  methods: {
    debounceRefresh: () => {
      // 由mounted钩子传入替代方法
    }
  },
  mounted() {
    // 防抖操作，防止图片加载完成后调用scroll的次数过于频繁
    this.debounceRefresh = debounce(this.$refs.scroll.refresh, 200)
    this.$bus.$on('itemImgLoad', this.debounceRefresh)
  }
}

export const backTopMixin = {
  components: {BackTop},
  data() {
    return {
      showBackTop: false
    }
  },
  methods: {
    /**
     * 回到顶部按钮的点击事件
     */
    backTopClick() {
      this.$refs.scroll.scrollTo(0, 0)
    },
    listenerShowBackTop(position) {
      this.showBackTop = (-position.y) > 1000
    }
  }

}
